import request from '@/utils/request'

// 楼层管理接口
export const floorApi = {
  // 获取楼层列表
  getList: (params?: {
    page?: number
    limit?: number
    venueId?: number
    keyword?: string
  }) => request.get('/admin/floors', { params }),

  // 获取楼层详情
  getDetail: (id: number) => request.get(`/admin/floors/${id}`),

  // 创建楼层
  create: (data: FormData) => request.post('/admin/floors', data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }),

  // 更新楼层
  update: (id: number, data: FormData) => request.put(`/admin/floors/${id}`, data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }),

  // 删除楼层
  delete: (id: number) => request.delete(`/admin/floors/${id}`),

  // 启用楼层
  enable: (id: number) => request.post(`/admin/floors/${id}/enable`),

  // 禁用楼层
  disable: (id: number) => request.post(`/admin/floors/${id}/disable`),

  // 上传平面图
  uploadFloorPlan: (id: number, file: File) => {
    const formData = new FormData()
    formData.append('floorPlan', file)
    return request.post(`/admin/floors/${id}/floor-plan`, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 删除平面图
  deleteFloorPlan: (id: number) => request.delete(`/admin/floors/${id}/floor-plan`)
}

// 楼层类型定义
export interface Floor {
  id: number
  venueId: number
  venue: {
    id: number
    name: string
    city: string
    country: string
  }
  name: string
  level?: number
  description?: string
  floorPlanUrl?: string
  status: 'ACTIVE' | 'INACTIVE'
  createdAt: string
  updatedAt: string
}

// 楼层创建/更新参数类型
export interface FloorFormData {
  venueId: number
  name: string
  level?: number
  description?: string
  status?: 'ACTIVE' | 'INACTIVE'
  floorPlan?: File
}

// 场馆选择选项类型
export interface VenueOption {
  id: number
  name: string
  city: string
  country: string
}
